package controllers;

import AlleSellerSecurity.Security;
import AlleSellerSecurity.SecurityProfile;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

public class LoginScreenController implements Initializable{
    @FXML
    TextField login;
    
    @FXML
    TextField password;
    
    @FXML
    private void handleLoginAction(ActionEvent event) {
        SecurityProfile profile = new SecurityProfile(login.getText(),password.getText());
        Security security = new Security();
        if(security.Login(profile))
        {
            Parent root;
            try {
                //root = FXMLLoader.load(getClass().getClassLoader().getResource("gui/Main.fxml"));
                FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/gui/mainLayout.fxml"));     

                root = (Parent)fxmlLoader.load();
                
                MainController controller = fxmlLoader.<MainController>getController();
                controller.initData(profile);
                
                Stage stage = new Stage();
                stage.setTitle("AlleSeller");
                stage.setScene(new Scene(root, 800, 600));
                
                stage.show();

                //hide this current window (if this is whant you want
                ((Node)(event.getSource())).getScene().getWindow().hide();

            } catch (IOException e) {
            }
        }
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        
    }
    
}
